﻿using System.Linq;
using System;

namespace MqttService.Code
{
    public static class MqttExtension
    {
        public static void AddMqtt(this IServiceCollection services)
        { 
            services.AddSingleton<IMqttInterface, MqttService>();
            services.AddSingleton<IMqttManager, MqttManager>();
        }

        public static void UseMqtt(this IApplicationBuilder app)
        {
            IServiceProvider serviceProvider = app.ApplicationServices; 
            IMqttInterface mqttRunner = serviceProvider.GetService<IMqttInterface>()!;
            mqttRunner?.StartAsync();
        }
    }
}
